package com.iwith.dongmoon.listadpater;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.iwith.dongmoon.activity.R;
import com.iwith.dongmoon.gsonlist.BoardListItem;

public class TwoTextListAdapter extends ArrayAdapter<BoardListItem> {
	private Context mContext;
	private ArrayList<BoardListItem> items;
	private LayoutInflater mInflater;

	public TwoTextListAdapter(Context context, int textViewResourceId, ArrayList<BoardListItem> list) {
		super(context, textViewResourceId, list);
		// TODO Auto-generated constructor stub

		this.mContext = context;
		this.items = list;
		this.mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	class ViewHolder {
		TextView subject;
		TextView datetime;
	}

	@Override
	public BoardListItem getItem(int position) {
		if(items==null) 	return null;
		else 				return items.get(position);
	}
	
	@Override
	public int getCount(){
		if(items==null)		return 0;
		else				return super.getCount();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.listitem_twotext, null);
			holder.subject = (TextView) convertView.findViewById(R.id.listitemtwotext_text1);
			holder.datetime = (TextView) convertView.findViewById(R.id.listitemtwotext_text2);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final BoardListItem item = items.get(position);

		if (item != null) {
			holder.subject.setText(item.getWr_subject());
			holder.datetime.setText(item.getWr_datetime());
			convertView.setBackgroundColor((position & 1) == 1 ? 0xffececec : Color.WHITE);
		}

		return convertView;
	}

}